<?php
/**
 * Controller is the customized base controller class.
 * All controller classes for this application should extend from this base class.
 */
class Controller extends CController
{
	/**
	 * @var string the default layout for the controller view. Defaults to '//layouts/column1',
	 * meaning using a single column layout. See 'protected/views/layouts/column1.php'.
	 */
	public $layout='//layouts/column1';
	/**
	 * @var array context menu items. This property will be assigned to {@link CMenu::items}.
	 */
	public $menu=array();
	/**
	 * @var array the breadcrumbs of the current page. The value of this property will
	 * be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
	 * for more details on how to specify this property.
	 */
	public $breadcrumbs=array();

	/**
	* 根据Get的参数，返回不同类型的json数据
	* @param $request //get得到对象
	* @param $code //执行的结果码
	* @param $message //提示的信息
	* @param $data //需要返回的数据
	*/
    public function callbackMessage($request, $code, $message, $data) {
        $retrun = json_encode(array(
            'code' => $code,
            'msg' => $message,
            'data' => $data,
        ));
        if (!empty($request['callback'])) {
        	header('Content-type:application/x-javascript;charset=utf-8');
            echo $request['callback'] . '(' . $retrun . ');';
        } else {
        	header('Content-type:application/json;charset=utf-8');
            echo $retrun;
        }
        // exit;
    }
    /**
     * [toArrays description]
     * @param  [type] $objects    [description]
     * @param  [type] $attributes [description]
     * @return [type]             [description]
     */
    public function toArrays($objects, $attributes)
    {
    	$list = array();
		foreach ($objects as $obj) {
		    $list[] = $obj->getAttributes($attributes);
		}
		return $list;
    }
    /**
     * [toArray description]
     * @param  [type] $objects    [description]
     * @param  [type] $attributes [description]
     * @return [type]             [description]
     */
    public function toArray($object, $attributes)
    {
		return $object->getAttributes($attributes);
    }
}